package cn.edu.zut.internship.service.impl.sys;


import cn.edu.zut.internship.entity.AuthSysMenu;
import cn.edu.zut.internship.entity.AuthSysMenuMeta;
import cn.edu.zut.internship.entity.AuthSysUser;
import cn.edu.zut.internship.iservice.sys.IAuthService;
import cn.edu.zut.internship.iservice.sys.IMenuService;
import cn.edu.zut.internship.iservice.sys.IUserService;
import cn.edu.zut.internship.mapper.sys.AuthSysMenuMetaMapper;
import cn.edu.zut.internship.mapper.sys.AuthSysPermissionMapper;
import cn.edu.zut.internship.mapper.sys.AuthSysRoleMapper;
import cn.edu.zut.internship.utils.EncryptUtil;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class AuthServiceImpl implements IAuthService {
    @Autowired
    private IMenuService menuService;
    @Autowired
    private IUserService userService;
    @Autowired
    private AuthSysRoleMapper roleMapper;
    @Autowired
    private AuthSysPermissionMapper permissionMapper;
    @Autowired
    private AuthSysMenuMetaMapper authSysMenuMetaMapper;
    @Override
    public List<AuthSysMenu> getMenus() {
        //查询所有路由表
        List<AuthSysMenu> firstMenus = menuService.findAllMenus();
        return firstMenus;
    }

    @Override
    public AuthSysUser verify(String username, String password) {
        AuthSysUser user = this.userService.findByUserName(username);
        if(user == null){
            throw new RuntimeException(username + "不存在");
        }else{
            password = EncryptUtil.getMD5Str(password);
            if(password.equals(user.getUrPassword())){
                return user;
            }
        }
        return null;
    }

}
